package com.yulin.activiti;

import java.io.IOException;

import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.util.EntityUtils;
import org.junit.Test;
import org.whale.bha.bean.request.BHAAccountInfoRequest;
import org.whale.bha.bean.response.BHAAccountInfoResponse;
import org.whale.bha.bean.type.BHAServiceNameEnum;
import org.whale.bha.util.BHAUtil;
import org.xml.sax.SAXException;

import com.google.gson.Gson;
import com.meterware.httpunit.GetMethodWebRequest;
import com.meterware.httpunit.HttpUnitOptions;
import com.meterware.httpunit.WebConversation;
import com.meterware.httpunit.WebRequest;
import com.meterware.httpunit.WebResponse;

public class TestBha {
	
    static{
//trying to make it to work....
            HttpUnitOptions.setScriptingEnabled(true);
            HttpUnitOptions.setExceptionsThrownOnScriptError(false);
            HttpUnitOptions.setDefaultCharacterSet("utf-8");
        }
    
	@Test
	public void test(){
		String platformNo = "10040011137";
		BHAAccountInfoRequest req = new BHAAccountInfoRequest();
		req.setPlatformNo(platformNo);
		req.setPlatformUserNo("asdfghjkl987654321");
		BHAAccountInfoResponse res = BHAUtil.doBHAService(BHAServiceNameEnum.ACCOUNT_INFO, BHAAccountInfoResponse.class, req);
		System.out.println(new Gson().toJson(res));
	}
	
	public static void main(String[] args) throws Exception {
        /*WebConversation wc = new WebConversation();
        wc.setHeaderField("Accept-Language", "zh-CN,zh;q=0.8");
        WebRequest     req =  new GetMethodWebRequest( "http://quote.eastmoney.com/sz002396.html" );
//        WebResponse   resp  = wc.sendRequest(req);
//        WebResponse   resp = wc.getResponse( req );
        WebResponse   resp  = wc.getResource(req);
        System.out.println(resp.getText());
        org.w3c.dom.Document doc =  resp.getDOM();
        System.out.println(doc.getTextContent());*/
        
        HttpClient httpClient = HttpClients.createDefault();  
        HttpGet get = new HttpGet("http://quote.eastmoney.com/sz002396.html");
        HttpResponse response = httpClient.execute(get);  
        HttpEntity entity = response.getEntity();  
        String responseContent = EntityUtils.toString(entity, "UTF-8");
        System.out.println(responseContent);
        //PostMethod method=new PostMethod(url);
//        GetMethod method=new GetMethod(url);
//        int status=client.executeMethod(method);
//        if(status==HttpStatus.SC_OK){
//            String html=method.getResponseBodyAsString();
//            Document doc=Jsoup.parse(html);
//            System.out.println(doc.toString());
//        }else{
//            System.err.println("URL Exception");
//        }
	}
	
}
